<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>智游问答-注册新用户</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
</head>

<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
                    aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">智游问答</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                    <li><a href="#">Link</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                            aria-expanded="false">操作 <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">Separated link</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">One more separated link</a></li>
                        </ul>
                    </li>
                </ul>
                <form class="navbar-form navbar-left">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Search">
                    </div>
                    <button type="submit" class="btn btn-default">Submit</button>
                </form>
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#">Link</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                            aria-expanded="false">操作 <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">注册</a></li>
                            <li><a href="signin.html">登录</a></li>
                            <li><a href="#">头像</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">退出</a></li>
                        </ul>
                    </li>
                </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav>
    <div class="container">
        <h3>注册新用户</h3>
        <form action="/user/register">
            <label for="petname">昵&#x3000;&#x3000;称：</label>
            <div class="form-group">
                <input type="text" class="form-control" name="petname" id="petname" pattern="^[0-9a-zA-Z\u4e00-\u9fa5]{2,18}$"
                    placeholder="请输入用户昵称">
            </div>
            <label for="password">密&#x3000;&#x3000;码：</label>
            <div class="form-group">
                <input type="password" class="form-control" name="password" id="password" pattern="^.{6,16}$"
                    placeholder="请输入您的密码">
            </div>
            <label for="confirmPassword">确认密码：</label>
            <div class="form-group">
                <input type="password" class="form-control" id="confirmPassword" pattern="^.{6,16}$" placeholder="请再次输入密码">
            </div>
            <label for="male">男</label>
            <input type="radio" name="isMale" id="male" value="true" checked>
            <label for="female">女</label>
            <input type="radio" name="isMale" id="female">
            <br>
            <label for="email">电子邮箱：</label>
            <div class="form-group">
                <input type="email" class="form-control" name="email" id="email" placeholder="请输入您的电子邮箱">
            </div>
            <label for="course">选修课程：</label>
            <div class="form-group">
                <select name="course" id="course" class="form-control">
                    <option value="HTML5" selected>HTML5</option>
                    <option value="PHP">PHP</option>
                    <option value="Java">Java</option>
                </select>
            </div>
            <div class="form-group">
                <input type="submit" class="form-control btn btn-success" value="注册">
            </div>
        </form>
    </div>
    <script src="bootstrap/js/jquery.js"></script>
    <script src="bootstrap/js/bootstrap.js"></script>
    <script>
        $('form').submit(function (e) {
            e.preventDefault();

            // 判断两次输入的密码是否一致
            var pass = $(':password')
            console.log(pass[0]);
            if (pass[0].value === pass[1].value) {
                $.post(
                    $(this).attr('action'),
                    $(this).serialize(),
                    function (res) {
                        console.log(res);
                        if (res.code === 'success') {
                            location.href = '/signin.html';
                        } else {
                            alert(res.message);
                        }
                    }
                )
            } else {
                alert('两次输入的密码不一致，请检查后重新输入');
            }
        });
    </script>
</body>

</html>